$(function () {
    var websocket = null;
    var isCanConfirm = true;
    var patchType = 3;

    var betwebsocket = null;
    var count_down = 0;

    initWebSocket();
    initBetSocket();

    queryRecordResult(patchType);
    // var ip = "localhost:9090";
    var ip = "100club.in";

    var webSokectUrl = "ws://" + ip + "/wsdemo";

    // 初始化开奖websocket
    function initBetSocket() {
        // var ip = "localhost:9090";
        var ip = "100club.in";
        var betSocketUrl = "ws://" + ip + "/ws_bet";
        //判断当前浏览器是否支持WebSocket ,主要此处要更换为自己的地址
        if ('WebSocket' in window) {
            console.log('websocket init success')
            betwebsocket = new WebSocket(betSocketUrl);
        } else {
            outMessage('Not support websocket')
        }
        //连接发生错误的回调方法
        betwebsocket.onerror = function () {
            outMessage("error");
        };
        //连接成功建立的回调方法
        betwebsocket.onopen = function (event) {
            outMessage("open");
        }

        //接收到消息的回调方法
        betwebsocket.onmessage = function (event) {
            prizesMessage(event.data);
        }

        //连接关闭的回调方法
        betwebsocket.onclose = function () {
            outMessage("close");
        }
    }

    // 初始化玩法websocket
    function initWebSocket() {
        // var ip = "localhost:9090";
        var ip = "100club.in";
        switch (patchType) {
            case 0:
                webSokectUrl = "ws://" + ip + "/wsparity";
                break;
            case 1:
                webSokectUrl = "ws://" + ip + "/wssapre";
                break;
            case 2:
                webSokectUrl = "ws://" + ip + "/wsbcone";
                break;
            case 3:
                webSokectUrl = "ws://" + ip + "/wsdemo";
                break;
        }


        //判断当前浏览器是否支持WebSocket ,主要此处要更换为自己的地址
        if ('WebSocket' in window) {
            console.log('websocket init success')
            websocket = new WebSocket(webSokectUrl);
        } else {
            outMessage('Not support websocket')
        }
        //连接发生错误的回调方法
        websocket.onerror = function () {
            outMessage("error");
        };
        //连接成功建立的回调方法
        websocket.onopen = function (event) {
            outMessage("open");
        }

        //接收到消息的回调方法
        websocket.onmessage = function (event) {
            setMessageInnerHTML(event.data);
        }

        //连接关闭的回调方法
        websocket.onclose = function () {
            outMessage("close");
        }
    }


    //监听窗口关闭事件，当窗口关闭时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。
    window.onbeforeunload = function () {
        websocket.close();
        closeBetSocket();
    }

    // 打印的消息
    function outMessage(innerHTML) {
        console.log(innerHTML);
    }

    function prizesMessage(innerHTML) {
        console.log("######################################");
        var obj = JSON.parse(innerHTML);
        console.log(obj.user)
        console.log(obj.prizes)
        var amount = (parseFloat(obj.user.balance)+parseFloat(obj.user.awayBalance==null?0:obj.user.awayBalance)).toFixed(2);
        console.log(amount)
        $("#user_balance_value").text(amount);
        // 中奖金额
        var m = parseFloat(obj.prizes);
        // 大于0就是中奖了  提示
        if (m > 0) {
            toast('WIN : ' + m)
        }
    }

    //将消息显示在网页上
    function setMessageInnerHTML(innerHTML) {
        // console.log(innerHTML)
        var obj = JSON.parse(innerHTML);
        // 期码
        var patchNum = obj.patchNum;
        count_down = obj.countDown;
        // 设置样式
        if (count_down <= 5) {
            isCanConfirm = false;
            $("#join_red_btn").addClass("btn_disable");
            $("#join_green_btn").addClass("btn_disable");
            $("#join_violet_btn").addClass("btn_disable");
            $(".touch_effect").addClass("btn_disable");


            $(".digit_red_violet").removeClass("line_color_red_violet")
            $(".digit_green_violet").removeClass("line_color_green_violet")
            $(".digit_red").removeClass("line_color_red")
            $(".digit_green").removeClass("line_color_green")

        } else {
            isCanConfirm = true;
            $("#join_red_btn").removeClass("btn_disable");
            $("#join_green_btn").removeClass("btn_disable");
            $("#join_violet_btn").removeClass("btn_disable");
            $(".touch_effect").removeClass("btn_disable");

            $(".digit_red_violet").addClass("line_color_red_violet")
            $(".digit_green_violet").addClass("line_color_green_violet")
            $(".digit_red").addClass("line_color_red")
            $(".digit_green").addClass("line_color_green")
        }

        if (count_down == 0) {
            setInterval(queryRecordResult(patchType), 1000);
        }

        var patchNum = obj.patchNum;
        // 设置显示的数字
        setHis(parseInt(count_down));
        $("#bot_ol").text(patchNum);
    }


    // 获取开奖结果
    function queryRecordResult(type) {
        var data = {type: type};
        $.ajax({
            type: "get",
            url: "../patch/queryAwardPatch",
            dataType: "json",
            contentType: "application/json",
            data: data,
            success: function (msg) {
                console.log(msg.data)
                var l = msg.data;
                var html = "";
                var prizesnum = 0;
                for (var i = 0; i < l.length; i++) {
                    var n = l[i];
                    var patchNum = n.patchNum.substring(n.patchNum.length - 3);
                    var pn = parseInt(n.prizesNum);
                    if (pn == 0 || pn == 5) {
                        html = "<li data-v-53f33387=\"\">\n" +
                            "<div data-v-53f33387=\"\" class=\"record_td\">\n" +
                            "<div data-v-53f33387=\"\" class=\"record_title\">" + patchNum + "</div>\n" +
                            "<div data-v-53f33387=\"\" class=\"record_body green_violet\">\n" + n.prizesNum + "</div>\n" +
                            "</div>\n" +
                            "</li>" + html;
                    } else if (pn == 1 || pn == 3 || pn == 7 || pn == 9) {
                        html = "<li data-v-53f33387=\"\">\n" +
                            "<div data-v-53f33387=\"\" class=\"record_td\">\n" +
                            "<div data-v-53f33387=\"\" class=\"record_title\">" + patchNum + "</div>\n" +
                            "<div data-v-53f33387=\"\" class=\"record_body green\">\n" + n.prizesNum + "</div>\n" +
                            "</div>\n" +
                            "</li>" + html;
                    } else {
                        html = "<li data-v-53f33387=\"\">\n" +
                            "<div data-v-53f33387=\"\" class=\"record_td\">\n" +
                            "<div data-v-53f33387=\"\" class=\"record_title\">" + patchNum + "</div>\n" +
                            "<div data-v-53f33387=\"\" class=\"record_body red\">\n" + n.prizesNum + "</div>\n" +
                            "</div>\n" +
                            "</li>" + html;
                    }
                    if (i == 0) {
                        prizesnum = parseInt(patchNum) + 1;
                    }
                }
                html += "<li data-v-53f33387=\"\">\n" +
                    " <div data-v-53f33387=\"\" class=\"record_td\">\n" +
                    "<div data-v-53f33387=\"\" class=\"record_title\">" + prizesnum + "</div>\n" +
                    " <div data-v-53f33387=\"\" class=\"record_body gray\">\n" +
                    "  ?\n" +
                    "</div>\n" +
                    "</div>\n" +
                    "</li>"
                $("#awardResult").html(html);
            }
        })
    }

    // 设置显示的数字
    function setHis(times = 0) {
        if (typeof times === 'number') {
            if (times <= 0) {
                return '00:00:00';
            } else {
                let hh = parseInt(times / 3600); //小时
                let shh = times - hh * 3600;
                let ii = parseInt(shh / 60);
                let ss = shh - ii * 60;

                hh = hh < 10 ? '0' + hh : hh;
                ii = ii < 10 ? '0' + ii : ii;
                ss = ss < 10 ? '0' + ss : ss;
                if (ii > 0) {
                    var countDownIiArr = ii.toString().split('');
                    var iia = countDownIiArr[0];
                    var iib = countDownIiArr[1];
                    if (countDownIiArr.length == 1) {
                        iia = 0;
                        iib = countDownArr[0];
                    }
                    $("#iia").text(iia);
                    $("#iib").text(iib);
                } else {
                    $("#iia").text('0');
                    $("#iib").text('0');
                }

                if (ss >= 0) {
                    var countDownArr = ss.toString().split('');
                    var mma = countDownArr[0];
                    var mmb = countDownArr[1];
                    if (countDownArr.length == 1) {
                        mma = 0;
                        mmb = countDownArr[0];
                    }
                    $("#mma").text(mma);
                    $("#mmb").text(mmb);
                }
            }
        } else {
            console.log('00:00:00')
        }
    }


    //关闭连接
    function closeWebSocket() {
        websocket.close();
    }

    function closeBetSocket() {
        betwebsocket.close();
    }


    //发送消息

    function send() {
        var message = document.getElementById('text').value;
        websocket.send(message);
    }

    // 初始化数据
    function initData() {
        $("#amount_hide").val(10);// 初始金额
        $("#multiple_hide").val(1); // 初始倍数
    }

    initData();

    $(".main_nav li").click(function () {
        patchType = parseInt($(this).attr("lang"));
        console.log(patchType)
        var vipLevel = $("#user_vip_level").val();
        if (parseInt(vipLevel) == 0 && parseInt(patchType) != 3) {
            $("#buyVip").css("display", "flex");
            return;
        }
        closeWebSocket();
        $(".main_nav li").removeClass("active");
        $(this).addClass("active");
        initWebSocket();

        queryRecordResult(patchType);
    });


    $("#buyVipClose").click(function () {
        $("#buyVip").css("display", "none");
    });

    $("#buyVipBtn").click(function () {
        window.location.href = "recharge";
    });


    $("#icon_question").click(function () {
        window.location.href = "winHelp"
    });


    // win websocket
    // 绿色0 红色2  中间1
    var color = 0;
    // number
    var betNumber = 0;
    // 默认费用
    var cost = 10;
    // 红色下单
    $("#join_red_btn").click(function () {
        if (!isCanConfirm) {
            return
        }
        $("#agree_zz_red").removeAttr("style")
        color = 2;
        $("#multiple_hide").val(1)
        $(".win_amount").text("₹19.6");
        $(".win_fee").text("₹0.3");
    })

    // 绿色下单
    $("#join_green_btn").click(function () {
        if (!isCanConfirm) {
            return
        }

        $("#agree_zz_green").removeAttr("style");
        color = 0;
        $("#multiple_hide").val(1);
        $(".win_amount").text("₹19.6");
        $(".win_fee").text("₹0.3");
    })

    // join_violet_btn
    $("#join_violet_btn").click(function () {
        if (!isCanConfirm) {
            return
        }
        var img = $(this).find("#violet_mask_btn");
        if (img.length > 0) {
            return;
        }
        $("#agree_zz_violet").removeAttr("style");
        color = 1;
        $("#multiple_hide").val(1);
        $(".win_amount").text("₹43.65");
        $(".win_fee").text("₹0.3");
    })

    $(".touch_effect").click(function () {
        var t = $.trim($(this).text());
        // 设置NUMBER
        $("#joinNumber").text(t);
        if (!isCanConfirm) {
            return
        }
        $("#agree_zz_number").removeAttr("style");
        color = 0;
        betNumber = t;
        $("#multiple_hide").val(1);
        $(".win_amount").text("87.3");
        $(".win_fee").text("₹0.3");
    });

    // 红色确认订单
    $("#red_confirm_btn").click(function () {
        confirmFun('0');
    })


    // 红色确认订单
    $("#green_confirm_btn").click(function () {
        confirmFun('0');
    })

    // violet 订单
    $("#violet_confirm_btn").click(function () {
        confirmFun('0');
    })

    // number 订单

    $("#number_confirm_btn").click(function () {
        confirmFun('1');
    })

    // 支付  下单
    function confirmFun(betType) {
        console.log("isCanConfirm : " + isCanConfirm)
        if (!isCanConfirm) {
            toast("it last to bet");
            setTimeout(function () {
                $("#agree_zz_red").css({"display": "none"})
                $("#agree_zz_green").css({"display": "none"})
                $("#agree_zz_violet").css({"display": "none"})
                $("#agree_zz_number").css({"display": "none"})
            }, 200);
            return;
        }
        // 期码
        var qm = $("#bot_ol").text();
        var data = {
            betColor: color,
            betCost: cost,
            betNumber: betNumber,
            patchType: patchType,
            betType: betType,
            countDown: count_down,
            periodCode: qm
        }

        var userBalance = $("#user_balance").val() == null ? '0' : $("#user_balance").val();
        var awayBalance = $("#away_balance").val() == null ? '0' : $("#away_balance").val();
        var balance = parseFloat(userBalance) + parseFloat(awayBalance);
        if (parseFloat(balance) < parseFloat(cost)) {
            toast("Insufficient balance!")
            return;
        }

        // 确认并提交订单
        $.ajax({
            type: "POST",
            url: "../bet/userBet",
            dataType: "json",
            contentType: "application/json",
            data: JSON.stringify(data),
            success: function (msg) {
                console.log(msg.success)
                var flag = msg.success;
                var data = msg.data;
                var clientUser = msg.data.clientUser;
                console.log("=====================")
                console.log(clientUser.balance)
                console.log(clientUser.awayBalance)
                if (flag) {
                    toast('SUCCESS');
                    $("#user_balance").val(clientUser.balance);
                    $("#away_balance").val(clientUser.awayBalance);
                    var yue = (parseFloat(clientUser.balance) + parseFloat(clientUser.awayBalance)).toFixed(2);
                    console.log(yue)
                    $("#user_balance_value").html(parseFloat(yue));
                    setTimeout(function () {
                        $("#agree_zz_red").css({"display": "none"})
                        $("#agree_zz_green").css({"display": "none"})
                        $("#agree_zz_violet").css({"display": "none"})
                        $("#agree_zz_number").css({"display": "none"})
                    }, 500);

                }
            }
        })
    }

    $(document).click(function (event) {
        var _con = $('#join_red_btn');   // 设置目标区域
        var _copy_red = $("#agree_zz_red");
        var _copy_green = $("#agree_zz_green");
        var _copy_violet = $("#agree_zz_violet");
        var _copy_number = $("#agree_zz_number");
        var _con_out = $(".red");
        var flag = false;
        if (!_con.is(event.target) && _con.has(event.target).length === 0) {
            flag = true;
        } else {
            return;
        }

        if (_copy_red.is(event.target) || _copy_green.is(event.target) || _copy_violet.is(event.target) || _copy_number.is(event.target)) {
            flag = true
        } else {
            return;
        }

        if (!_con_out.is(event.target) && _con_out.has(event.target).length === 0) {
            flag = true;
        } else {
            return;
        }
        if (flag) {
            $("#agree_zz_red").css({"display": "none"})
            $("#agree_zz_green").css({"display": "none"})
            $("#agree_zz_violet").css({"display": "none"})
            $("#agree_zz_number").css({"display": "none"})
        }
    });

    $(".amount_li").click(function () {
        var amount = $(this).text();
    });


    $("#hdrefreshBtn").click(function () {
        window.location.reload();
    });

    // number -----------
    $(".amount_number_li").click(function () {
        $(".amount_number_li").removeClass("amount_select");
        $(this).addClass("amount_select");
        var amount = $(this).text();
        $("#amount_hide").val(amount)
        //Confirm ₹10
        // 获取倍数
        var multiple = $("#multiple_hide").val(); // 初始倍数
        var confirm_amount = parseInt(amount) * parseInt(multiple);
        cost = confirm_amount;
        $("#number_confirm_btn").text('Confirm ₹' + confirm_amount);

        // 计算赢多少
        var winamount = parseFloat(confirm_amount) * 9 - (parseFloat(confirm_amount) * 0.03 * 9);
        $(".win_amount").text("₹" + winamount);
        var winFee = (parseFloat(confirm_amount) * 0.03).toFixed(2);
        $(".win_fee").text("₹" + winFee);
    });


    $(".multiple_number_li").click(function () {
        $(".multiple_number_li").removeClass("multiple_select");
        $(this).addClass("multiple_select")
        var amount = $("#amount_hide").val();
        var multiple = parseInt($(this).text());
        //
        $("#multiple_hide").val(multiple);
        $("#multiple_number_input").val(multiple);
        var confirm_amount = parseInt(amount) * parseInt(multiple);
        cost = confirm_amount;
        $("#number_confirm_btn").text('Confirm ₹' + confirm_amount);

        // 计算赢多少
        var winamount = parseFloat(confirm_amount) * 9 - (parseFloat(confirm_amount) * 0.03 * 9);
        $(".win_amount").text("₹" + winamount);
        var winFee = (parseFloat(confirm_amount) * 0.03).toFixed(2);
        $(".win_fee").text("₹" + winFee);
    })


    $("#number_add_btn").click(function () {
        addOrMinusNumber(1)
    });

    $("#number_minus_btn").click(function () {
        addOrMinusNumber(0)
    });

    function addOrMinusNumber(type) {
        $(".multiple_number_li").removeClass("multiple_select");
        var amount = parseInt($("#amount_hide").val()); // 初始金额
        var multiple = parseInt($("#multiple_hide").val()); // 初始倍数
        var addMultiple = 0;
        if (type == 1) {
            addMultiple = multiple + 1;
        } else {
            addMultiple = multiple - 1;
            if (addMultiple < 1) {
                return;
            }
        }
        var li = "multiple_number_li_";
        if (addMultiple == 2 || addMultiple == 4 || addMultiple == 8 || addMultiple == 16) {
            li = li + addMultiple;
            $("#" + li).addClass("multiple_select")
        }
        var confirm_amount = parseInt(amount) * addMultiple;
        $("#multiple_hide").val(addMultiple);
        $("#multiple_number_input").val(addMultiple);
        $("#number_confirm_btn").text('Confirm ₹' + confirm_amount);

        // 计算赢多少
        var winamount = parseFloat(confirm_amount) * 9 - (parseFloat(confirm_amount) * 0.03 * 9);
        $(".win_amount").text("₹" + winamount);
        var winFee = (parseFloat(confirm_amount) * 0.03).toFixed(2);
        $(".win_fee").text("₹" + winFee);
    }


    // 绿色----
    $(".amount_green_li").click(function () {
        $(".amount_green_li").removeClass("amount_select");
        $(this).addClass("amount_select")
        var amount = $(this).text();
        //
        $("#amount_hide").val(amount)
        //Confirm ₹10
        // 获取倍数
        var multiple = $("#multiple_hide").val(); // 初始倍数
        var confirm_amount = parseInt(amount) * parseInt(multiple);
        cost = confirm_amount;
        $("#green_confirm_btn").text('Confirm ₹' + confirm_amount);

        // 计算赢多少
        var winamount = parseFloat(amount) * 2 - (parseFloat(amount) * 0.03 * 2);
        $(".win_amount").text("₹" + winamount);
        var winFee = (parseFloat(confirm_amount) * 0.03).toFixed(2);
        $(".win_fee").text("₹" + winFee);
    })

    $(".multiple_green_li").click(function () {
        $(".multiple_green_li").removeClass("multiple_select");
        $(this).addClass("multiple_select")
        var amount = $("#amount_hide").val();
        var multiple = parseInt($(this).text());
        //
        $("#multiple_hide").val(multiple);
        $("#multiple_green_input").val(multiple);
        var confirm_amount = parseInt(amount) * parseInt(multiple);
        cost = confirm_amount;
        $("#green_confirm_btn").text('Confirm ₹' + confirm_amount);

        // 计算赢多少
        var winamount = parseFloat(confirm_amount) * 2 - (parseFloat(confirm_amount) * 0.03 * 2);
        $(".win_amount").text("₹" + winamount);
        var winFee = (parseFloat(confirm_amount) * 0.03).toFixed(2);
        $(".win_fee").text("₹" + winFee);
    })


    $("#green_add_btn").click(function () {
        addOrMinusGreen(1)
    });

    $("#green_minus_btn").click(function () {
        addOrMinusGreen(0)
    });

    function addOrMinusGreen(type) {
        $(".multiple_green_li").removeClass("multiple_select");
        var amount = parseInt($("#amount_hide").val()); // 初始金额
        var multiple = parseInt($("#multiple_hide").val()); // 初始倍数
        var addMultiple = 0;
        if (type == 1) {
            addMultiple = multiple + 1;
        } else {
            addMultiple = multiple - 1;
            if (addMultiple < 1) {
                return;
            }
        }
        var li = "multiple_green_li_";
        if (addMultiple == 2 || addMultiple == 4 || addMultiple == 8 || addMultiple == 16) {
            li = li + addMultiple;
            $("#" + li).addClass("multiple_select")
        }
        var confirm_amount = parseInt(amount) * addMultiple;
        $("#multiple_hide").val(addMultiple);
        $("#multiple_green_input").val(addMultiple);
        $("#green_confirm_btn").text('Confirm ₹' + confirm_amount);

        // 计算赢多少
        var winamount = parseFloat(confirm_amount) * 2 - (parseFloat(confirm_amount) * 0.03 * 2);
        $(".win_amount").text("₹" + winamount);
        var winFee = (parseFloat(confirm_amount) * 0.03).toFixed(2);
        $(".win_fee").text("₹" + winFee);
    }


    // 红色----
    $(".amount_red_li").click(function () {
        $(".amount_red_li").removeClass("amount_select");
        $(this).addClass("amount_select")
        var amount = $(this).text();
        //
        $("#amount_hide").val(amount)
        //Confirm ₹10
        // 获取倍数
        var multiple = $("#multiple_hide").val(); // 初始倍数
        var confirm_amount = parseInt(amount) * parseInt(multiple);
        cost = confirm_amount;
        $("#red_confirm_btn").text('Confirm ₹' + confirm_amount);

        // 计算赢多少
        var winamount = parseFloat(amount) * 2 - (parseFloat(amount) * 0.03 * 2);
        $(".win_amount").text("₹" + winamount);
        var winFee = (parseFloat(confirm_amount) * 0.03).toFixed(2);
        $(".win_fee").text("₹" + winFee);
    })

    $(".multiple_red_li").click(function () {
        $(".multiple_red_li").removeClass("multiple_select");
        $(this).addClass("multiple_select")
        var amount = $("#amount_hide").val();
        var multiple = parseInt($(this).text());
        //
        $("#multiple_hide").val(multiple);
        $("#multiple_red_input").val(multiple);
        var confirm_amount = parseInt(amount) * parseInt(multiple);
        cost = confirm_amount;
        $("#red_confirm_btn").text('Confirm ₹' + confirm_amount);

        // 计算赢多少
        var winamount = parseFloat(confirm_amount) * 2 - (parseFloat(confirm_amount) * 0.03 * 2);
        $(".win_amount").text("₹" + winamount);
        var winFee = (parseFloat(confirm_amount) * 0.03).toFixed(2);
        $(".win_fee").text("₹" + winFee);
    })


    $("#red_add_btn").click(function () {
        addOrMinusRed(1)
    });

    $("#red_minus_btn").click(function () {
        addOrMinusRed(0)
    });

    function addOrMinusRed(type) {
        $(".multiple_red_li").removeClass("multiple_select");
        var amount = parseInt($("#amount_hide").val()); // 初始金额
        var multiple = parseInt($("#multiple_hide").val()); // 初始倍数
        var addMultiple = 0;
        if (type == 1) {
            addMultiple = multiple + 1;
        } else {
            addMultiple = multiple - 1;
            if (addMultiple < 1) {
                return;
            }
        }
        var li = "multiple_red_li_";
        if (addMultiple == 2 || addMultiple == 4 || addMultiple == 8 || addMultiple == 16) {
            li = li + addMultiple;
            $("#" + li).addClass("multiple_select")
        }
        var confirm_amount = parseInt(amount) * addMultiple;
        $("#multiple_hide").val(addMultiple);
        $("#multiple_red_input").val(addMultiple);
        $("#red_confirm_btn").text('Confirm ₹' + confirm_amount);

        // 计算赢多少
        var winamount = parseFloat(confirm_amount) * 2 - (parseFloat(confirm_amount) * 0.03 * 2);
        $(".win_amount").text("₹" + winamount);
        var winFee = (parseFloat(confirm_amount) * 0.03).toFixed(2);
        $(".win_fee").text("₹" + winFee);
    }


    // violet ----
    $(".amount_violet_li").click(function () {
        $(".amount_violet_li").removeClass("amount_select");
        $(this).addClass("amount_select")
        var amount = $(this).text();
        //
        $("#amount_hide").val(amount)
        //Confirm ₹10
        // 获取倍数
        var multiple = $("#multiple_hide").val(); // 初始倍数
        var confirm_amount = parseInt(amount) * parseInt(multiple);
        cost = confirm_amount;
        $("#violet_confirm_btn").text('Confirm ₹' + confirm_amount);


        // 计算赢多少
        var winamount = parseFloat(confirm_amount) * 4.5 - (parseFloat(confirm_amount) * 0.03 * 4.5);
        $(".win_amount").text("₹" + winamount);
        var winFee = (parseFloat(confirm_amount) * 0.03).toFixed(2);
        $(".win_fee").text("₹" + winFee);
    })

    $(".multiple_violet_li").click(function () {
        $(".multiple_violet_li").removeClass("multiple_select");
        $(this).addClass("multiple_select")
        var amount = $("#amount_hide").val();
        var multiple = parseInt($(this).text());
        //
        $("#multiple_hide").val(multiple);
        $("#multiple_violet_input").val(multiple);
        var confirm_amount = parseInt(amount) * parseInt(multiple);
        cost = confirm_amount;
        $("#violet_confirm_btn").text('Confirm ₹' + confirm_amount);

        // 计算赢多少
        var winamount = parseFloat(confirm_amount) * 4.5 - (parseFloat(confirm_amount) * 0.03 * 4.5);
        $(".win_amount").text("₹" + winamount);
        var winFee = (parseFloat(confirm_amount) * 0.03).toFixed(2);
        $(".win_fee").text("₹" + winFee);
    })


    $("#violet_add_btn").click(function () {
        addOrMinusViolet(1)
    });

    $("#violet_minus_btn").click(function () {
        addOrMinusViolet(0)
    });


    $("#moreRecord").click(function () {
        window.location.href = "redGreenRecords?patchType=" + patchType;
    });

    function addOrMinusViolet(type) {
        $(".multiple_violet_li").removeClass("multiple_select");
        var amount = parseInt($("#amount_hide").val()); // 初始金额
        var multiple = parseInt($("#multiple_hide").val()); // 初始倍数
        var addMultiple = 0;
        if (type == 1) {
            addMultiple = multiple + 1;
        } else {
            addMultiple = multiple - 1;
            if (addMultiple < 1) {
                return;
            }
        }
        var li = "multiple_violet_li_";
        if (addMultiple == 2 || addMultiple == 4 || addMultiple == 8 || addMultiple == 16) {
            li = li + addMultiple;
            $("#" + li).addClass("multiple_select")
        }
        var confirm_amount = parseInt(amount) * addMultiple;
        $("#multiple_hide").val(addMultiple);
        $("#multiple_violet_input").val(addMultiple);
        $("#violet_confirm_btn").text('Confirm ₹' + confirm_amount);


        // 计算赢多少
        var winamount = parseFloat(confirm_amount) * 4.5 - (parseFloat(confirm_amount) * 0.03 * 4.5);
        $(".win_amount").text("₹" + winamount);
        var winFee = (parseFloat(confirm_amount) * 0.03).toFixed(2);
        $(".win_fee").text("₹" + winFee);
    }


    $("#violet_mask_btn").click(function () {
        $("#buyVip").css("display", "flex");
    })
    $("#novip_mask_btn").click(function () {
        $("#buyVip").css("display", "flex");
    })
})